--
-- Created by IntelliJ IDEA.
-- User: Administrator
-- Date: 2021/5/30
-- Time: 14:12
-- To change this template use File | Settings | File Templates.
--
JSON = (loadfile "./script/JSON.lua")()

function show_baidu()
    local request = http:new_request()
    request:set_url("http://www.baidu.com")
    request:set_timeout(1)
    local response = http:send(request)
    if response:is_err() then
        print("请求错误：",response:error())
        return
    end
    print("success",response:status(),response:version())
    print("content-type:",response:get_header("content-type"))
    print("header:")
    for key, value in pairs(response:headers()) do
        if key ~= "body" then
            print("     ",key,value)
        end
    end
end

function main(thread_index)
    print("--->",thread_index,"request: www.baidu.com","<---")
    show_baidu()
end

return main